package br.com.takashii.lp.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;

public class MailUtil {


	public void sendMimeMail(final String assunto, final String mensagem) {
		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
		mailSender.setHost("smtp.evertical.com.br");
		mailSender.setPort(587);
		mailSender.setUsername("tsilva@evertical.com.br");
		mailSender.setPassword("ts56&");
		mailSender.send(new MimeMessagePreparator() {
			public void prepare(MimeMessage mimeMessage)
					throws MessagingException {
				MimeMessageHelper message;
				try {
					message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
					message.setFrom("tsilva@evertical.com.br");
					List<String> emails = new ArrayList<String>();//
					emails.add("takashii.rsilva@gmail.com");
					message.setTo((String[]) emails.toArray(new String[0]));
					message.setSubject(assunto);
					message.setSentDate(new Date());
					message.setText(mensagem, true);
				} catch (MessagingException e) {
					e.printStackTrace();
				}
			}
		});
	}
}
